package com.cm.caseManagement.controller;

import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmApplyRecord;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmApplyRecordService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 申报记录Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/record")
public class CmApplyRecordController extends BaseController
{
    @Autowired
    private ICmApplyRecordService cmApplyRecordService;

    /**
     * 查询申报记录列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmApplyRecord cmApplyRecord)
    {
        startPage();
        List<CmApplyRecord> list = cmApplyRecordService.selectCmApplyRecordList(cmApplyRecord);
        return getDataTable(list);
    }

    /**
     * 导出申报记录列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:record:export')")
    @Log(title = "申报记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmApplyRecord cmApplyRecord)
    {
        List<CmApplyRecord> list = cmApplyRecordService.selectCmApplyRecordList(cmApplyRecord);
        ExcelUtil<CmApplyRecord> util = new ExcelUtil<CmApplyRecord>(CmApplyRecord.class);
        util.exportExcel(response, list, "申报记录数据");
    }

    /**
     * 获取申报记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmApplyRecordService.selectCmApplyRecordById(id));
    }

    /**
     * 新增申报记录
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:record:add')")
    @Log(title = "申报记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmApplyRecord cmApplyRecord)
    {
        return toAjax(cmApplyRecordService.insertCmApplyRecord(cmApplyRecord));
    }

    /**
     * 修改申报记录
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:record:edit')")
    @Log(title = "申报记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmApplyRecord cmApplyRecord)
    {
        return toAjax(cmApplyRecordService.updateCmApplyRecord(cmApplyRecord));
    }

    /**
     * 删除申报记录
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:record:remove')")
    @Log(title = "申报记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmApplyRecordService.deleteCmApplyRecordByIds(ids));
    }
}
